
#include <boost/test/unit_test.hpp>


#define _DEBUGING
#include "../MemoryManagerForAllocatorPoolBased.h"

#include <vector>
using namespace std;


class FixtureTestMemoryManagerForAllocatorPoolBased
{
public:


    FixtureTestMemoryManagerForAllocatorPoolBased()
    {


    }

};


BOOST_FIXTURE_TEST_CASE( TestMemoryManagerForAllocatorPoolBased_1, FixtureTestMemoryManagerForAllocatorPoolBased)
{


    static const unsigned int _HowManyAllocatorsInManager=5;
    static const unsigned int _HowmanyHandlesMemory=8000;
    static const unsigned int _loops=100;
    static const unsigned int _PoolSize=100;

    typedef MemoryManagerForAllocatorPoolBased<_HowManyAllocatorsInManager,_HowmanyHandlesMemory, int> Manager;
    Manager manager;






    for(int i=0;i<_loops;i++)
    {
        Manager::HandleAllocator tabHandleAllocator[_HowManyAllocatorsInManager];

        for(int j=0;j<_HowManyAllocatorsInManager;j++)
        {
            tabHandleAllocator[j]=manager.acquireHandleAllocator();
        }

        for(int j=0;j<_HowManyAllocatorsInManager;j++)
        {
            manager.dereferenceHandleAllocator( tabHandleAllocator[j])->reset(new Manager::Allocator(_PoolSize));
        }

        Manager::HandleAllocatorMemory tabHand[_HowManyAllocatorsInManager*_PoolSize];


        for(int j=0;j<_HowManyAllocatorsInManager;j++)
        {
            for(int k=0;k<_PoolSize;k++)
            {
                tabHand[j*_PoolSize+k]=manager.acquireHandleAllocatorMemory(tabHandleAllocator[j]);
                *manager.dereferenceHandleAllocatorMemory(tabHand[j*_PoolSize+k])=j*_PoolSize+k;
            }
        }

        for(int j=0;j<_HowManyAllocatorsInManager;j++)
        {
            for(int k=0;k<_PoolSize;k++)
            {
                
                BOOST_CHECK(*manager.dereferenceHandleAllocatorMemory(tabHand[j*_PoolSize+k])==j*_PoolSize+k);

            }
        }

        for(int j=0;j<_HowManyAllocatorsInManager;j++)
        {
            for(int k=0;k<_PoolSize;k++)
            {
                manager.releaseHandleAllocatorMemory(tabHand[j*_PoolSize+k]);
            }
        }

       for(int j=0;j<_HowManyAllocatorsInManager;j++)
        {
            manager.releaseHandleAllocator( tabHandleAllocator[j]);
        }

    }


}
